﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace MultiWallpaperManager
{
	/// <summary>
	/// 이미지 리스트 박스를 위해 만듬.
	/// </summary>
	public class ImageItem
	{
		private static float ThumbnailScale = 1 / 4;

		private string fileName;
		private string filePath;
		private Image thumbnail;
		private Size size;

		public ImageItem(string name, string filePath)
		{
			this.fileName = name;
			this.filePath = filePath;

			Image image = null;

			// load image and get image size
			try
			{
				image = Image.FromFile(filePath);
			}
			catch (Exception)
			{
				MessageBox.Show(string.Format(Resource.CannotLoadFile, filePath), Resource.MessageBoxTitle);
			}

			thumbnail = image.GetThumbnailImage((int)(image.Width * ThumbnailScale),
												(int)(image.Height * ThumbnailScale), null, new IntPtr());

			size.Width = image.Size.Width;
			size.Height = image.Size.Height;

			image.Dispose();
		}

		~ImageItem()
		{
			thumbnail.Dispose();
		}

		public string FileName
		{
			get { return fileName; }
		}

		public string FilePath
		{
			get { return filePath; }
		}

		// display name
		public override string ToString()
		{
			return FileName;
		}

		public int Width
		{
			get { return size.Width; }
		}

		public int Height
		{
			get { return size.Height; }
		}

		public Image Thumbnail
		{
			get { return thumbnail; }
		}

	}
}
